package lanou.autohome.recommend.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;
import lanou.autohome.recommend.beans.SpeakerBean;

/**
 * Created by dllo on 16/8/18.
 */
public class SpeakAdapter extends RecyclerView.Adapter<SpeakAdapter.MyViewHolder> {

    Context mcontext;
    SpeakerBean speakerBean;

    public SpeakAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setSpeakerBean(SpeakerBean speakerBean) {
        this.speakerBean = speakerBean;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mcontext).inflate(R.layout.item_recommend_speak , null);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        holder.time.setText(speakerBean.getResult().getList().get(position).getTime());
        holder.title.setText(speakerBean.getResult().getList().get(position).getTitle());
        holder.replycount.setText(String.valueOf(speakerBean.getResult().getList().get(position).getReplycount()) + "评论");

        NetTool netTool = new NetTool();
        netTool.getImage(speakerBean.getResult().getList().get(position).getSmallpic(), holder.smallpic);

    }

    @Override
    public int getItemCount() {
        return speakerBean != null ? speakerBean.getResult().getList().size() : 0;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        ImageView smallpic;
        TextView title;
        TextView time;
        TextView replycount;
        public MyViewHolder(View itemView) {
            super(itemView);
            smallpic = (ImageView) itemView.findViewById(R.id.smallpic_recommend_speaker_item);
            title = (TextView) itemView.findViewById(R.id.title_recommend_speaker_item);
            time = (TextView) itemView.findViewById(R.id.time_recommend_speaker_item);
            replycount = (TextView) itemView.findViewById(R.id.replycount_recommend_speaker_item);
        }
    }
}
